<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="数据日期" prop="sjrq">
        <el-date-picker
          v-model="queryParams.sjrq"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="date"
          range-separator="-"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['buss:jxxtlsb:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="jxxtlsbList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="数据日期" align="center" prop="sjrq"  />
      <el-table-column label="行员代号" align="center" prop="hydh"   />
      <el-table-column label="机构号" align="center" prop="orgId"  />
      <el-table-column label="行员名称" align="center" prop="hymc"   />
      <el-table-column label="活期存款笔数" align="center" prop="hqckbs" />
      <el-table-column label="活期存款余额" align="center" prop="hqckye"   />
      <el-table-column label="定期存款笔数" align="center" prop="dqckbs"   />
      <el-table-column label="定期存款余额" align="center" prop="dqckye"   />
      <el-table-column label="存款年日均" align="center" prop="cknrj"   />
      <el-table-column label="贷款笔数" align="center" prop="dkbs"   />
      <el-table-column label="贷款余额" align="center" prop="dkye"   />
      <el-table-column label="贷款年日均" align="center" prop="dknrj"   />
      <el-table-column label="理财金额" align="center" prop="lcxsje"   />
      <el-table-column label="手机银行户数" align="center" prop="sjyhhs"   />
      <el-table-column label="pos户数" align="center" prop="poshs"   />
      <el-table-column label="第三方支付户数" align="center" prop="dsfqyhs"   />
      <el-table-column label="有效贷记卡" align="center" prop="yxdjkbs"   />
      <el-table-column label="etc笔数" align="center" prop="etcbbs"   />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['buss:jxxtlsb:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['buss:jxxtlsb:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改营销业绩统计历史，每天保存4.1.2对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listJxxtlsb, getJxxtlsb, delJxxtlsb, addJxxtlsb, updateJxxtlsb } from "@/api/buss/jxxtlsb";

export default {
  name: "Jxxtlsb",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 营销业绩统计历史，每天保存4.1.2表格数据
      jxxtlsbList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sjrq: null,
        hydh: null,
        orgId: null,
        hymc: null,
        hqckbs: null,
        hqckye: null,
        dqckbs: null,
        dqckye: null,
        cknrj: null,
        dkbs: null,
        dkye: null,
        dknrj: null,
        lcxsje: null,
        sjyhhs: null,
        poshs: null,
        dsfqyhs: null,
        yxdjkbs: null,
        etcbbs: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询营销业绩统计历史，每天保存4.1.2列表 */
    getList() {
      this.loading = true;
      listJxxtlsb(this.queryParams).then(response => {
        this.jxxtlsbList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        sjrq: null,
        hydh: null,
        orgId: null,
        hymc: null,
        hqckbs: null,
        hqckye: null,
        dqckbs: null,
        dqckye: null,
        cknrj: null,
        dkbs: null,
        dkye: null,
        dknrj: null,
        lcxsje: null,
        sjyhhs: null,
        poshs: null,
        dsfqyhs: null,
        yxdjkbs: null,
        etcbbs: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.sjrq)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加营销业绩统计历史，每天保存4.1.2";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const sjrq = row.sjrq || this.ids
      getJxxtlsb(sjrq).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改营销业绩统计历史，每天保存4.1.2";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.sjrq != null) {
            updateJxxtlsb(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addJxxtlsb(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const sjrqs = row.sjrq || this.ids;
      this.$confirm('是否确认删除营销业绩统计历史，每天保存4.1.2编号为"' + sjrqs + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delJxxtlsb(sjrqs);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('buss/reportLsb/exportYxyjtjbService', {
        ...this.queryParams
      }, `营销业绩统计.xlsx`)
    }
  }
};
</script>
